//
//  SearchViewController.m
//  QYer
//
//  Created by lanou on 16/8/10.
//  Copyright © 2016年 CaiZhuYu. All rights reserved.
//

#import "SearchViewController.h"

@interface SearchViewController ()<UISearchBarDelegate>

@property (nonatomic, strong) UISearchBar *searchBar;
@property (nonatomic, strong) NSMutableArray *dataArray;
@property (nonatomic, strong) UICollectionView *collectionView;


@end

@implementation SearchViewController

- (NSMutableArray *)dataArray {
    if (!_dataArray) {
        _dataArray = [NSMutableArray array];
    }
    return _dataArray;
}


- (void)requestData {
    NSString *urlString = @"http://open.qyer.com/qyer/search/hot_history?client_id=qyer_ios&client_secret=cd254439208ab658ddf9&count=20&oauth_token=94beceb249a77955076cf273c95e67af&page=1&track_app_channel=App%2520Store&track_app_version=7.0&track_device_info=iPhone%25205%28ChinaMobile%2CChinaTelecom%2CChinaUnicom%29&track_deviceid=2D9E8D6C-2140-49DC-993D-D66133CC22C0&track_os=ios%25209.3.2&track_user_id=8252405&v=1";
    [NetWorkTool requstWithType:GET URLString:urlString parameter:nil callBack:^(NSData *data, NSError *error) {
        NSDictionary *jsonDic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
        //NSLog(@"数据: %@", jsonDic[@"data"]);
        self.dataArray = jsonDic[@"data"];
        
    }];
}

- (void)createSubViews {
    
    
}


#pragma mark -----

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor yellowColor];
    
    self.searchBar = [[UISearchBar alloc] init];
    self.navigationItem.titleView = self.searchBar;
    self.searchBar.delegate = self;
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"取消" style:UIBarButtonItemStylePlain target:self action:@selector(cancelAction)];
    
    
    [self requestData];
    
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)cancelAction {
    [self dismissViewControllerAnimated:YES completion:nil];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/


#pragma mark -----

- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar {
    return YES;
}





@end
